<!--
 * @Description: 讲师列表
 * @Autor: dyx
 * @Date: 2023-01-31 17:24:42
 * @LastEditTime: 2023-02-08 14:33:17
-->
<template>
  <div>
    <el-dialog
      title="讲师列表"
      :close-on-click-modal="false"
      :visible.sync="teacherVisible"
      class="JADP-dialog JADP-dialog_center"
      lock-scroll
      width="70%"
      v-loading="loading"
      append-to-body
    >
      <div class="JADP-common-layout-center">
        <el-row class="JADP-common-search-box" :gutter="16">
          <el-form @submit.native.prevent>
            <el-col :span="6">
              <el-form-item label="姓名">
                <el-input
                  v-model="query.realname"
                  placeholder="请输入"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col>

            <el-col :span="6">
              <el-form-item label="任教科目">
                <el-input
                  v-model="query.teachingsubjects"
                  placeholder="请输入"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col>

            <!-- <el-col :span="6">
              <el-form-item label="技能等级">
                <el-input
                  v-model="query.skilllevel"
                  placeholder="请输入"
                  clearable
                >
                </el-input>
              </el-form-item>
            </el-col> -->
            <el-col :span="6">
              <el-form-item>
                <el-button
                  type="primary"
                  icon="el-icon-search"
                  @click="search()"
                  >查询</el-button
                >
                <el-button icon="el-icon-refresh-right" @click="reset()"
                  >重置</el-button
                >
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
        <div class="JADP-common-layout-main JADP-flex-main">
          <el-table
            v-loading="listLoading"
            :data="list"
            @sort-change="sortChange"
            highlight-current-row
            @current-change="handleSelectionChange"
            :row-style="{cursor: 'pointer'}"
          >
            <el-table-column type="index" width="50"> </el-table-column>
            <el-table-column
              prop="realname"
              label="姓名"
              width="0"
              align="left"
            />
            <el-table-column prop="gender" label="性别" width="0" align="left">
              <template v-slot="{ row }">
                {{ getDict("sex", row.gender) }}
              </template>
            </el-table-column>
            <el-table-column
              prop="birthday"
              label="出生年月"
              width="0"
              align="left"
            />
            <el-table-column
              prop="politicallandscape"
              label="政治面貌"
              width="0"
              align="left"
            />
            <el-table-column
              prop="certificatesnumber"
              label="身份证号码"
              width="0"
              align="left"
            />
            <el-table-column
              prop="education"
              label="文化程度"
              width="0"
              align="left"
            >
              <template v-slot="{ row }">
                {{ getDict("Education", row.education) }}
              </template>
            </el-table-column>

            <el-table-column
              prop="worktime"
              label="工作时间"
              width="0"
              align="left"
              sortable="custom"
            />
            <el-table-column
              prop="technicaltitle"
              label="技术职称"
              width="0"
              align="left"
              show-overflow-tooltip
            />
            <el-table-column
              prop="xzjob"
              label="行政职务"
              width="0"
              align="left"
              show-overflow-tooltip
            />
            <el-table-column
              prop="skilllevel"
              label="技能等级"
              width="0"
              align="left"
              sortable="custom"
              show-overflow-tooltip
            />
            <el-table-column
              prop="teachingsubjects"
              label="任教科目"
              width="0"
              align="left"
              show-overflow-tooltip
            />
          </el-table>
          <pagination
            :total="total"
            :page.sync="listQuery.currentPage"
            :limit.sync="listQuery.pageSize"
            @pagination="initData"
          />
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="teacherVisible = false">取 消</el-button>
        <el-button type="primary" @click="determine">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import request from "@/utils/request";

export default {
  name: "teacherList",
  data() {
    return {
      teacherVisible: false,
      loading: false,
      listLoading: false,
      list: [],
      multipleSelection: [],
      total: 0,
      query: {
        realname: undefined,
        technicaltitle: undefined,
        teachingsubjects: undefined,
        worktype: undefined,
        certificatesnumber: undefined,
        major: undefined,
        skilllevel: undefined
      },
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      }
    };
  },
  created() {
    this.initData();
  },
  methods: {
    //查询
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: "creatortime"
      };
      this.initData();
    },
    //重置
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.search();
    },
    // 确定
    determine() {
      this.$emit("determine", this.multipleSelection);
      this.teacherVisible = false;
    },
    handleSelectionChange(val) {
      //   const res = val.map(item => item.id);
      this.multipleSelection = val;
      console.log(val);
    },
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },
    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        organizeId:this.$store.getters.organizeId
      };
      request({
        url: `/api/teachersManage/Xy_ks_teachers/getList`,
        method: "post",
        data: _query
      })
        .then(res => {
          var _list = [];
          for (let i = 0; i < res.data.list.length; i++) {
            let _data = res.data.list[i];
            _list.push(_data);
          }
          this.list = _list;
          this.total = res.data.pagination.total;
          this.listLoading = false;
        })
        .catch(err => {
          this.$message.error(err.msg);
          this.listLoading = false;
        });
    }
  }
};
</script>
<style scoped lang="scss"></style>
